﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Daphne.GameShared;

namespace GameEngine.MoveGenerators
{
    public class ShortKingMoveGenerator: BaseKingMoveGenerator
    {
        /// <summary>
        /// Returns positions to move for short-range kings
        /// </summary>
        protected override List<Position> GetKingStepsInDiagonal(Position figurePos, enumDiagonalDir dir)
        {
            List<Position> list = new List<Position>();
            Position testPos = figurePos.GetNextField(dir);
            if (IsPlaceFreeToMove(testPos))
                list.Add(testPos);

            return list;          
        }

        /// <summary>
        /// Generates jumps for short-range king in one direction
        /// </summary>
        protected override List<Position> CheckKingJumpsInDirection(Position pos, enumDiagonalDir dir, enumFigureColor clrMovedFigure)
        {
            List<Position> destFields = new List<Position>();
            Position testPos = pos.GetNextField(dir);

            if(GameBoard.IsOutsideBoard(testPos) == false)
            {
                if (IsPlaceFreeToMove(testPos) == false)
                {
                    // figure of the same color?
                    if (GameBoard.GetField(testPos.Row, testPos.Col).FigureColor() == clrMovedFigure)
                        return destFields;
                    // check if next field is free to jump at
                    testPos = testPos.GetNextField(dir);

                    if (IsPlaceFreeToMove(testPos))
                    {
                        destFields.Add(testPos);
                    }
                }
            }

            return destFields;
        }

    }
}
